﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Xml;

namespace iLangl
{
	public class SerializationHelper
	{
		public static string SerializeOject(object obj)
		{
			XmlSerializer xml = new XmlSerializer(obj.GetType());
			StringWriter swriter = new StringWriter();
			XmlTextWriter writer = new XmlTextWriter(swriter);
			xml.Serialize(writer, obj);
			string result = swriter.GetStringBuilder().ToString();
			writer.Close();
			swriter.Close();
			return result;
		}

		public static object DeserializeObject(string obj, Type type)
		{
			XmlSerializer xml = new XmlSerializer(type);
			StringReader sr = new StringReader(obj);
			XmlTextReader reader = new XmlTextReader(sr);
			object result = xml.Deserialize(reader);
			reader.Close();
			sr.Close();
			return result;
		}

	}
}
